\documentclass[ntfdMod]{elsarticle}
\usepackage{graphicx}
\usepackage{color}
\usepackage[numbered,bw]{mcode}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{hyperref}
\usepackage{esint}
\usepackage[protrusion=true,expansion]{microtype}
\hypersetup{
	bookmarks=true,         % show bookmarks bar?
	unicode=false,          % non-Latin characters in Acrobat’s bookmarks
	pdftoolbar=true,        % show Acrobat’s toolbar?
	pdfmenubar=true,        % show Acrobat’s menu?
	pdffitwindow=false,     % window fit to page when opened
	pdfstartview={FitH},    % fits the width of the page to the window
	pdftitle={My title},    % title
	pdfauthor={Author},     % author
	pdfsubject={Subject},   % subject of the document
	pdfcreator={Creator},   % creator of the document
	pdfproducer={Producer}, % producer of the document
	pdfkeywords={keyword1} {key2} {key3}, % list of keywords
	pdfnewwindow=true,      % links in new window
	colorlinks=true,       % false: boxed links; true: colored links
	linkcolor=red,          % color of internal links
	citecolor=green,        % color of links to bibliography
	filecolor=magenta,      % color of file links
	urlcolor=cyan           % color of external links
}
\usepackage{verbatim}
\sloppy
\definecolor{lightgray}{gray}{0.5}
\setlength{\parindent}{0pt}

\title{Small post processor}
\begin{document}
\maketitle

    
    
\section{Contents}

\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item Clear complete workspace
   \item Read data files
   \item Set neccessary parameters
   \item Compute 3D spectrum
   \item Compute dissipation and turbulent kinetic energy
   \item Verify computation of kinetic Energy
   \item Kolmogrov properties
   \item Compute model spectra
   \item Compute correlations
\end{itemize}


\section{Clear complete workspace}

\begin{par}
For Matlab projects the best practise is to clear the complete workspace and the command window also closing all figures might be helpful. In the subsequent you may also define some neccessary flags distinguishing bewteen different data sets.
\end{par} \vspace{1em}
\begin{verbatim}
path('./functions',path) % add functions directory the Matlab path
ClearWs();
\end{verbatim}
\begin{par}

The content of \verb|ClearWs| reads
\lstinputlisting{../functions/ClearWs.m}

\end{par} \vspace{1em}


\section{Read data files}

\begin{par}

Read in the data files and measure the time for reading. The output of
the tic/toc block is in seconds. What you should get from the tic/toc
block is that most of the time is spend during data I/O. The actual
computation needs only ??? compared to the time of the I/O operations.
One of the most important part of all postprocessors is to read the files
that actually contain your data. Although in terms of speed and size the
ASCII
data format ist not the prefered choice, for this purpose we will use this
format to make ease the understanding. For your information one very
famous and highly protable data format is
\href{http://www.hdfgroup.org/HDF5/}{hdf5}. Besides its hierarchical
structure
it is highly optimized for parallel I/O operations which are essential
for DNS simulations.

\end{par} \vspace{1em}
\begin{verbatim}
[uvel,vvel,wvel,time_read] = ReadData(datadir,flag);
\end{verbatim}
\begin{par}

The content of \verb|ReadData| reads
\lstinputlisting{../functions/ReadData.m}

\end{par} \vspace{1em}


\section{Set neccessary parameters}

\begin{par}
\begin{verbatim}latex\end{verbatim} For further computations it is important to define some parmeters of the DNS simulation such as domain size, grid spacing, and the number of grid points.
\end{par} \vspace{1em}
\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item Number of grid points in on direction $n_{px}$
   \item Physical length of one direction $L_x$
   \item Physical grid spacing $\delta\,x$
   \item Kinematic viscosity $\nu$
\end{itemize}
\begin{par}
\begin{verbatim}/latex\end{verbatim}
\end{par} \vspace{1em}
\begin{verbatim}
    dim=256; % number of points in one dimension
    Lx=5e-3; % domain size
    Ly=Lx;
    Lz=Lx;
    dx=Lx/dim; % grid spacing
    dy=dx;
    dz=dx;
    nu=1.7e-5; % viscosity
    u=reshape(uvel,dim,dim,dim); % reshape arrays to have them in 3D
    v=reshape(vvel,dim,dim,dim);
    w=reshape(wvel,dim,dim,dim);
    clear uvel vvel wvel
\end{verbatim}


\section{Compute 3D spectrum}

\begin{par}
In order to avoid aliasing effects usually connected with a one dimensional spectrum it is also possible to produce correlations that involve all possible directions. The three dimensional Fourier transformation of such a correlation produces a spectrum that not only depends on a single wavenumber but on the wavenumber vector $\kappa_i$. Though the directional information contained in $\kappa_i$ eliminates the aliasing problem the complexity makes a physical reasoning impossible. For homogeneous isotropic turbulence the situation can be simplified by integrating the three dimensional spectrum over spherical shells.
\end{par} \vspace{1em}
\begin{par}

  \begin{equation}
      E(\kappa) = \oiint E(\boldsymbol\kappa)\mathrm{d}S(\kappa)
                = \oiint \frac{1}{2}\,Phi_{ii}(\boldsymbol\kappa)\mathrm{d}S(\kappa)
  \end{equation}
  Since the surface of a sphereis completly determined by its radius the
  surface integral can be solved analytically.
  \begin{equation}
      \oiint(\,)\mathrm{d}S(\kappa) = 4\pi\kappa^2\cdot(\,)
  \end{equation}
This leads to
  \begin{equation}
      E(|\kappa|) = \frac{1}{2}\,\Phi_{ii}(|\boldsymbol\kappa|)
  \end{equation}

\end{par} \vspace{1em}
\begin{verbatim}
[spectrum,k,mu,mv,mw] = power_spec(u,v,w,Lx);
\end{verbatim}


\section{Compute dissipation and turbulent kinetic energy}

\begin{verbatim}
[Dissipation,kinetic_E] = spec_prop(spectrum,k,nu);
\end{verbatim}


\section{Verify computation of kinetic Energy}

\begin{verbatim}
up = sqrt(1/3*(u.^2+v.^2+w.^2));
kinetic_Up = sum(sum(sum(3/2*up.^2)))/size(up,1)^3;
\end{verbatim}


\section{Kolmogrov properties}

\begin{verbatim}
eta = (nu^3/Dissipation)^(1/4);
u_eta = (nu*Dissipation)^(1/4);
tau = (nu/Dissipation)^(1/2);
\end{verbatim}


\section{Compute model spectra}

\begin{par}
Von Karman-Pao Spektren
\end{par} \vspace{1em}
\begin{verbatim}
close all
kd = k(end);
ke = pi/Lx/2;
A = 1.5;
up = mean2(up);

VKP1 = A*up^5/Dissipation.*(k./ke).^4./(1+(k./ke).^2).^(17/6).*exp(-3/2*A.*(k./kd).^(4/3));

kd = 1./eta;
VKP2 = 1.5*(k./kd).^(-5/3)./(Dissipation*nu^5)^(-1/4).*exp(-1.5*1.5.*(k./kd).^(4/3));

% Kolmogorov Spektrum
Kolmo=1.5*Dissipation^(2/3)*(k.^(-5/3));

% Plot spectra
h=loglog(k,Kolmo,k,VKP1,k,VKP2,k,spectrum);
set(h,'LineWidth',2);

h=legend('Kolmogorov','VKP1','VKP2','Computed');
set(h,'Location','SouthWest')
\end{verbatim}


\section{Compute correlations}

\begin{par}
Computing a correlation can be a tedious work (requireing tremendeous effort) especially if you have large data sets. From theory it is well known that the multiplication of the transform of a data set and its complex conjugate are an accurate representation of the correlation function. Using the FFT approach this gives an enormeous speed advantage. Since we already computed the veloity correlation tensor we may use this result in order to compute the correlation tensor.
\end{par} \vspace{1em}
\begin{par}

  \begin{equation}
      R_{ij} = \frac{cov(U_i,U_j)}{\sqrt{\sigma_i^2\,\sigma_j^2}}
             = \frac{(u_i'-\mu_i)\,(u_j-\mu_j)}{\sqrt{\sigma_i^2\,\sigma_j^2}}
  \end{equation}

\end{par} \vspace{1em}
\begin{verbatim}
[R11,R22,r,R1,R2,R3]=correlation(u,v,w,Lx);
\end{verbatim}



\end{document}
    
